package ldh.im.base.service;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import ldh.common.PageResult;
import ldh.im.base.dao.ImDepartmentDao;
import ldh.im.base.pojo.ImDepartment;
import ldh.im.base.pojo.where.ImDepartmentWhere;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: ldh
 * @date: 2024-03-21 10:36:16
*/
@Service("imDepartmentService")
public class ImDepartmentService {

	@Resource
	private ImDepartmentDao imDepartmentDao;
	
	@Transactional
	public ImDepartment insert(ImDepartment imDepartment) {
		int n = imDepartmentDao.insert(imDepartment);
		if (n != 1) {
			throw new RuntimeException("ImDepartment insert error!");
		}
		return imDepartment;
	}
	
	@Transactional
	public ImDepartment insertSelective(ImDepartment imDepartment) {
		int n = imDepartmentDao.insert(imDepartment);
		if (n != 1) {
			throw new RuntimeException("ImDepartment insertSelective error!");
		}
		return imDepartment;
	}

	@Transactional
	public ImDepartment updateById(ImDepartment imDepartment) {
		int  n = imDepartmentDao.updateById(imDepartment);
		if (n != 1) {
			throw new RuntimeException("ImDepartment update error!");
		}
        return imDepartment;
     }

	@Transactional
	public ImDepartment updateNotNullById(ImDepartment imDepartment) {
		int  n = imDepartmentDao.updateNotNullById(imDepartment);
		if (n != 1) {
			throw new RuntimeException("ImDepartment update error!");
		}
        return imDepartment;
     }


    @Transactional
    public void deleteById(Long id) {
		int n = imDepartmentDao.deleteById(id);
		if (n != 1) {
			throw new RuntimeException("ImDepartment delete error!");
		}
    }

	@Transactional(readOnly = true)
	public ImDepartment getById(Long id) {
		ImDepartment imDepartment = imDepartmentDao.getById(id);
		return imDepartment;
    }
    
	
	@Transactional(readOnly = true)
	public PageResult<ImDepartment> findByImDepartmentWhere(ImDepartmentWhere imDepartmentWhere) {
		long total = imDepartmentDao.findTotalByImDepartmentWhere(imDepartmentWhere);
		List<ImDepartment> imageList = new ArrayList<ImDepartment>();
		if (total > 0) {
			imageList  = imDepartmentDao.findByImDepartmentWhere(imDepartmentWhere);
		}
		
		return new PageResult<ImDepartment>(imDepartmentWhere, total, imageList);
	}
	
	
}
